package com.tao.system.controller.exam;

import com.tao.common.creo.controller.BaseController;
import com.tao.common.creo.domain.Result;
import com.tao.common.creo.domain.TableDataInfo;
import com.tao.system.domain.exam.dto.ExamAddDTO;
import com.tao.system.domain.exam.dto.ExamQueryDTO;
import com.tao.system.domain.exam.dto.ExamQuestionAddDTO;
import com.tao.system.domain.exam.vo.ExamDetailVO;
import com.tao.system.domain.exam.vo.ExamVO;
import com.tao.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛接口", description = "该组是关于竞赛的操作的接口")
public class examController extends BaseController {
    @Autowired
    IExamService examService;

    /**
     * 获取竞赛列表
     * @param examQueryDTO 关于列表的一些参数
     * @return 竞赛列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    /**
     * 添加竞赛基本信息
     */
    @PostMapping("/add")
    public Result<String> add(@Validated ExamAddDTO examAddDTO) {
        return Result.success(examService.add(examAddDTO));
    }
    /**
     * 为竞赛添加题目
     */
    // todo 前端点击全选题目添加异常, 只能添加题目id为18题目, 待解决
    @PostMapping("/question/add")
    public Result<Void> questionAdd(@RequestBody ExamQuestionAddDTO questionAddDTO) {
        return toResult(examService.questionAdd(questionAddDTO));
    }

    /**
     * 删除竞赛下的题目
     * @param examId
     * @param questionId
     * @return
     */
    @DeleteMapping("/question/delete")
    public Result<Void> questionDelete(Long examId, Long questionId) {
        return toResult(examService.questionDelete(examId, questionId));
    }

    /**
     * 获取竞赛信息
     * @param examId 竞赛id
     * @return 竞赛的详情 竞赛基础信息和题目列表信息
     */
    @GetMapping("/detail")
    public Result<ExamDetailVO> detail( Long examId) {
        return Result.success(examService.detail(examId));
    }

    /**
     * 发布竞赛
     * @param examId 竞赛id
     * @return
     */
    @PutMapping("/publish")
    public Result<Void> publish(Long examId) {
        return toResult(examService.publish(examId));
    }

    /**
     * 撤销竞赛发布
     * @param examId 竞赛id
     * @return
     */
    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId) {
        return toResult(examService.cancelPublish(examId));
    }

    /**
     * 删除竞赛
     * @param examId 竞赛id
     * @return
     */
    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId) {
        return toResult(examService.delete(examId));
    }


}
